FROM php:8.1.29-fpm-bullseye

RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list 
RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

RUN apt-get update 
RUN apt-get install -y socat

ADD --chmod=0755 https://delivery.ulthon.com/install-php-extensions /usr/local/bin/

RUN install-php-extensions pdo_mysql
RUN install-php-extensions gd
RUN install-php-extensions fileinfo
RUN install-php-extensions opcache
RUN install-php-extensions redis
RUN install-php-extensions event
RUN install-php-extensions imagick
RUN install-php-extensions pcntl
RUN install-php-extensions bcmath

RUN mkdir -p /data/projects
RUN touch /usr/local/etc/php-fpm.d/zz-www.conf
RUN touch /usr/local/etc/php/php.ini

VOLUME ["/data/projects","/usr/local/etc/php-fpm.d/zz-www.conf","/usr/local/etc/php/php.ini"]

# 创建启动脚本
RUN echo '#!/bin/sh\n\
    php-fpm &\n\
    socat TCP-LISTEN:3570,fork TCP:host.docker.internal:3570 &\n\
    socat TCP-LISTEN:3800,fork TCP:host.docker.internal:3800 &\n\
    socat TCP-LISTEN:6379,fork TCP:host.docker.internal:6379 \n\
    wait' > /usr/local/bin/start.sh

# 赋予启动脚本执行权限
RUN chmod +x /usr/local/bin/start.sh

EXPOSE 9000

CMD ["/usr/local/bin/start.sh"]
